<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>
<%@ page import="java.net.URLEncoder" %>
<%!
    private String getDirectory(String orgid) {
        JdbcDao jdbcDao = Env.getBean("jdbcDao");
        List<Map<String, String>> directorys = jdbcDao.queryForList("select categorys from ut_deptcategory where deleted!=1 and dept=?", new Object[]{orgid});
        if (directorys.size() == 0) return null;
        else {
            return directorys.get(0).get("categorys");
        }
    }
%>
<%
    String orgid0 = StringUtil.null2String(request.getParameter("orgid"));
    if (!StringUtil.isEmpty(orgid0)) {
        String directoryid = getDirectory(orgid0);
        if (!StringUtil.isEmpty(directoryid))
            response.sendRedirect(request.getContextPath() + "/form/formprocess.jsp?orgid="+orgid0+"&directoryid=" + directoryid);
        return;
    }
    String orgids = loginUser.getOrgids();
    List<String> orgids_arr = StringUtil.string2ArrayList(orgids, ",");

    String url = "/form/formprocess1.jsp";

    if (orgids_arr.size() < 2) {
        orgid0 = loginUser.getOrgid();
        String directoryid = getDirectory(orgid0);
        if (!StringUtil.isEmpty(directoryid))
            response.sendRedirect(request.getContextPath() + "/form/formprocess.jsp?directoryid=" + directoryid);
        return;
    } else {
        OrgService orgService = Env.getBean("orgService");
%>
<html>
<head>
    <%@ include file="/common/head.jsp" %>
</head>
<body>
<table class="formtable">
    <colgroup>
        <col width="20%">
        <col width="80%">
    </colgroup>
    <tr>
        <td class="formlabel">请选择部门</td>
        <td><select id="orglist">
            <%for (String orgid : orgids_arr) {%>
            <option value="<%=orgid%>" <%if(orgid.equals(Env.getRemoteUser().getOrgid())){%>selected<%}%>><%=orgService.get(orgid).getObjname()%>
            </option>
            <%}%>
        </select>
        <button id="submitbtn">提交</button>
        </td>
    </tr>
</table>
<script type="text/javascript">
    $('#orglist').bind('change', function () {
            url = '<%=url%>' + '?orgid=' + this.value;
            onUrl(url, $("#orglist>option:selected").get(0).text);
    })
    $('#submitbtn').bind('click',function () {
                url = '<%=url%>' + '?orgid=' + $('#orglist').val();
                onUrl(url, $("#orglist>option:selected").get(0).text);
        })
</script>
</body>
</html>
<%}%>

